#include<bits/stdc++.h>
using namespace std;
const int N=2e5+99;
int n,m,q,k,e[N];
int uu[N],vv[N];
int cnt,ban[3009],vis[3009];
struct edge{
    int v,id,nxt;
}edg[N*2];
int cntedge,hd[N];
void add(int u,int v,int id){
    cntedge++;
    edg[cntedge]=(edge){v,id,hd[u]};
    hd[u]=cntedge;
}
int cyc[N],ok;
int sta[N],stacnt;
namespace special{
    void findcycle(int u,int lid){
        vis[u]=1; sta[++stacnt]=u;
        int v,id;
        for(int i=hd[u];i;i=edg[i].nxt){
            v=edg[i].v; id=edg[i].id;
            if(id==lid) continue;
            if(vis[v]){
                cyc[v]=1;
                while(sta[stacnt]!=v) cyc[sta[stacnt]]=1,stacnt--;
                ok=1; return;
            }
            else{
                findcycle(v,id);
                if(ok) return;
            }
        }
        stacnt--;
        return;
    }
    void solve(){
        findcycle(1,0);
        while(q--){
            cin>>k;
            for(int i=1;i<=k;i++)
                cin>>e[i];
            if(k>=2||!cyc[uu[e[1]]]||!cyc[vv[e[1]]]) cout<<"NO"<<'\n';
            else cout<<"YES"<<'\n';
        }
    }
}
namespace brute{
    void dfs(int u){
        vis[u]=1; cnt++;
        int v;
        for(int i=hd[u];i;i=edg[i].nxt){
            v=edg[i].v;
            if(vis[v]||ban[edg[i].id]) continue;
            dfs(v);
        }
    }
    void solve(){
        while(q--){
            memset(vis,0,sizeof(vis));
            cnt=0;
            cin>>k;
            for(int i=1;i<=k;i++){
                cin>>e[i];
                ban[e[i]]=1;
            }
            dfs(1);
            if(cnt==n) cout<<"YES"<<'\n';
            else cout<<"NO"<<'\n';
            for(int i=1;i<=k;i++)
                ban[e[i]]=0;
        }
    }
}
int main(){
    freopen("graph.in","r",stdin);
    freopen("graph.out","w",stdout);
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>uu[i]>>vv[i];
        add(uu[i],vv[i],i);
        add(vv[i],uu[i],i);
    }
    cin>>q;
    if(m==n) special::solve();
    else brute::solve();
    return 0;
}